#include<iostream>

using namespace std;




string reverseWords(string s)
{
        int end = s.size() - 1;

        while (end >= 0)
        {
            int pos = s.rfind(' ', end) + 1;
            reverse(s.begin() + pos, s.begin() + end + 1);
            end = pos - 2;
        }

        return s;
}


int main()
{
    string s("abc def ghi");

    cout << reverseWords(s) << endl;
	return 0;
}